<?php
/*************************************************************
*
*	@file:	include/class/items.class.php
*
*	@class:	items
*
*	@brief:	class that provide a whole support 
*				for items.
*
*	@author: Skype
*************************************************************/

class items
{
	/**
	*	@brief:	the error message
	*
	*	@access: public
	*
	*	@type: string
	*/
	public $error = '';

	/**
	*	@brief:	seller ID and item tags
	*
	*	@access: public
	*
	*	@type: string
	*/
	public $sellerID = '';

	public $tags = Array();

	/**
	*	@brief:	set the error message
	*
	*	@access: protected
	*
	*	@params: $error, string contain the message of error.
	*
	*	@return: none
	*/
	protected function setErrorMessage($error)
	{
		$this->error = $error;
	}

	/**
	 * 	@class constructor
	 */
	function __construct($sellerID)
	{
		if(!$sellerID) return FALSE;
		$this->sellerID = $sellerID;
	}

	/**
	*	@brief:	add an item
	*
	*	@access: public
	*
	*	@params: $uid, owner of item
	*					 $item, array contains the iteminfo
	*
	*	@return: item ID
	*/
	public function addItem($iteminfo)
	{
		if(!$iteminfo) return FALSE;

		$insertstr = '';
		$itemIDs = array();

		//insert the itemtable		
		foreach ($iteminfo as $key => $value)
			$insertstr = $insertstr."`{$key}` = '$value',";
		//$insertstr = substr($insertstr, 0, strlen($insertstr)-1);
		
		$queryinsert = <<<INS
INSERT 
INTO 
`{$GLOBALS['cfg']['database']['TablePrefix']}item` 
SET 
{$insertstr} 
`item_seller` = '{$this->seller}'
INS;
//echo $queryinsert;
		if ($result = $GLOBALS['db']->query($queryinsert))
			$newid = $GLOBALS['db']->insert_id;
		else
			return FALSE;
}
	
	/**
	*	@brief:	remove an item
	*
	*	@access: public
	*
	*	@params: $uid, owner of item
	*					 $itemid, id of the item
	*
	*	@return: boolean
	*/
	public function delItem($itemid)
	{
		if(!$itemid) return FALSE;
		
		//remove item
		$query = <<<DEL
DELETE 
FROM 
`{$GLOBALS['cfg']['database']['TablePrefix']}item` 
WHERE 
`item_id` = {$itemid}
AND
`item_seller` = '{$this->seller}'
DEL;
//echo $query;
		if (!$GLOBALS['db']->query($query))
			return FALSE;
		return TRUE;
	}
	
	/**
	*	@brief:	modify an item
	*
	*	@access: public
	*
	*	@params: $uid, owner of item
	*					 $item, array contains the new iteminfo
	*
	*	@return: boolean
	*/
	public function updateItem($itemid, $iteminfo)
	{
		
	}
	
	/**
	*	@brief:	set item tags
	*
	*	@access: public
	*
	*	@params: $tags array
	*
	*	@return: boolean
	*/
	public function setItemTags($tags)
	{
		$this->tags = $tags;
	}
	
	/**
	*	@brief:	add tags into table
	*
	*	@access: public
	*
	*	@params: 
	*
	*	@return: boolean
	*/
	protected function addTags()
	{
	}
	
}
?>
